package stock;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.hibernate.Session;
import org.springframework.stereotype.Component;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import stock.model.Sunfa20chengjiaoModel;

@Component
@SuppressWarnings("all")
public class Sunfa4 implements Sunfa4Interface {

	@Override
	public void jisuan20(JSONObject json) {
		// TODO Auto-generated method stub

		String day = json.getString("day");

		Float chaju1 = Float.parseFloat(json.getString("chaju1"));

		Float chaju2 = Float.parseFloat(json.getString("chaju2"));

		String sql = "select DISTINCT(t.code),t.diqv,t1.shizhi from stock t left join stock_gai_nian t1 on t1.code = t.code  where t1.shizhi >20 and t1.shizhi<200";

		Session session = ContextUtil.getSessionFactory1().openSession();
		List<Object[]> list = session.createSQLQuery(sql).list();

		String sql1 = "select t.huanshoulv from stock t  where t.code = ?0  ORDER BY t.date desc limit 0," + day;

		String sql2 = "select t.danqianjia from stock t  where t.code = ?0  ORDER BY t.date desc limit 0," + day;

		List<String> arr = new ArrayList<String>();

		for (int i = 0; i < list.size(); i++) {

			String code = list.get(i)[0] + "";

			List<Float> list1 = session.createSQLQuery(sql1).setParameter(0, code).list();
			List<Float> list2 = session.createSQLQuery(sql2).setParameter(0, code).list();

			if (list1.size() <= 0 || list1 == null || list2.size() <= 0 || list2 == null) {
				continue;
			}
			list1 = removeNulls(list1);
			list2 = removeNulls(list2);
			if (list1.size() <= 0 || list1 == null || list2.size() <= 0 || list2 == null) {
				continue;
			}
			boolean b = checkMaxMinDiff(list1, chaju1);
			boolean b1 = checkMaxMinDiff1(list2, chaju2);
			if (b && b1) {
				System.out.println("--------t20----算法" + code + "符合条件" + i);
				arr.add(code);
			} else {
				System.out.println("--------t20----算法" + code + "不符合条件" + i);
			}
		}
		System.out.println("共：" + arr.size());
		String joinedString = String.join(",", arr);
		System.out.println(joinedString);

		session.beginTransaction();
		Sunfa20chengjiaoModel sm = new Sunfa20chengjiaoModel();
		sm.setDate(DateTools.getCurrentDate("yyyyMMdd"));
		sm.setAllcode(joinedString);
		sm.setType("1");
		String sql10 = "delete from sunfa20chengjiao_model where type = '1' ";
		session.createSQLQuery(sql10).executeUpdate();
		session.save(sm);
		session.getTransaction().commit();
		session.clear();
		session.close();
	}

	public static boolean checkMaxMinDiff(List<Float> list, Float chaju1) {

		Float max = list.stream().max(Float::compare).get();
		Float min = list.stream().min(Float::compare).get();
		return max <= min * chaju1;
	}

	public static boolean checkMaxMinDiff1(List<Float> list, Float chaju2) {
		// Float max = list.stream().max(Float::compare).get();
		Float min = list.stream().min(Float::compare).get();
		Float c = list.get(0);
		return min * chaju2 <= c;
	}

	public static List<Float> removeNulls(List<Float> list) {
		List<Float> result = new ArrayList<>();
		for (Float value : list) {
			if (value != null) {
				result.add(value);
			}
		}
		return result;
	}

	@Override
	public void jisuan21(JSONObject json) {
		String day = json.getString("day");

		Float chaju1 = Float.parseFloat(json.getString("chaju3"));

		Float chaju2 = Float.parseFloat(json.getString("chaju4"));

		String sql = "select DISTINCT(t.code),t.diqv,t1.shizhi from stock t left join stock_gai_nian t1 on t1.code = t.code  where t1.shizhi >20 and t1.shizhi<200";

		Session session = ContextUtil.getSessionFactory1().openSession();
		List<Object[]> list = session.createSQLQuery(sql).list();

		String sql1 = "select t.huanshoulv from stock t  where t.code = ?0  ORDER BY t.date desc limit 0," + day;

		String sql2 = "select t.danqianjia from stock t  where t.code = ?0  ORDER BY t.date desc limit 0," + day;

		List<String> arr = new ArrayList<String>();

		for (int i = 0; i < list.size(); i++) {

			String code = list.get(i)[0] + "";

			List<Float> list1 = session.createSQLQuery(sql1).setParameter(0, code).list();
			List<Float> list2 = session.createSQLQuery(sql2).setParameter(0, code).list();

			if (list1.size() <= 0 || list1 == null || list2.size() <= 0 || list2 == null) {
				continue;
			}
			list1 = removeNulls(list1);
			list2 = removeNulls(list2);
			if (list1.size() <= 0 || list1 == null || list2.size() <= 0 || list2 == null) {
				continue;
			}
			boolean b = isGreater(list1, chaju1);
			boolean b1 = withinPercent(list2, chaju2);
			if (b && b1) {
				System.out.println("--------t20----算法" + code + "符合条件" + i);
				arr.add(code);
			} else {
				System.out.println("--------t20----算法" + code + "不符合条件" + i);
			}
		}
		System.out.println("共：" + arr.size());
		String joinedString = String.join(",", arr);
		System.out.println(joinedString);
		session.beginTransaction();
		Sunfa20chengjiaoModel sm = new Sunfa20chengjiaoModel();
		sm.setDate(DateTools.getCurrentDate("yyyyMMdd"));
		sm.setAllcode(joinedString);
		sm.setType("2");
		String sql10 = "delete from sunfa20chengjiao_model where type = '2' ";
		session.createSQLQuery(sql10).executeUpdate();
		session.save(sm);
		session.getTransaction().commit();
		session.clear();
		session.close();

	}

	// java List<Float> 第1，2，3条数据是之后所有数据的5倍以上，则返回true
	public static boolean isGreater(List<Float> list, Float chaju) {
		if (list.size() < 4) {
			return false;
		}

		float first = list.get(0);
		float second = list.get(1);
		float third = list.get(2);
		float sum = 0;

		for (int i = 3; i < list.size(); i++) {
			sum = list.get(i);
			boolean b = first > sum * chaju && second > sum * chaju && third > sum * chaju;
			if (b == false) {
				return false;
			}
		}
		return true;
	}

	// java List<Float> 第1，2，3条数据没有超过三者平均的+-5%
	public static boolean withinPercent(List<Float> list, Float chaju) {

		Float min = list.stream().min(Float::compare).get();
		Float c = list.get(0);
		return min * chaju <= c;
	}

	@Override
	public void jisuan22(JSONObject json) {
		String day = json.getString("day");

		Float chaju1 = Float.parseFloat(json.getString("chaju5"));

		Float chaju2 = Float.parseFloat(json.getString("chaju6"));

		Float chaju3 = Float.parseFloat(json.getString("chaju7"));

		String sql = "select DISTINCT(t.code),t.diqv,t1.shizhi from stock t left join stock_gai_nian t1 on t1.code = t.code  where t1.shizhi >20 and t1.shizhi<200";

		Session session = ContextUtil.getSessionFactory1().openSession();
		List<Object[]> list = session.createSQLQuery(sql).list();

		String sql1 = "select t.huanshoulv from stock t  where t.code = ?0  ORDER BY t.date desc limit 0," + day;

		String sql2 = "select t.zhandifu from stock t  where t.code = ?0  ORDER BY t.date desc limit 0," + day;

		List<String> arr = new ArrayList<String>();

		for (int i = 0; i < list.size(); i++) {

			String code = list.get(i)[0] + "";

			List<Float> list1 = session.createSQLQuery(sql1).setParameter(0, code).list();
			List<Float> list2 = session.createSQLQuery(sql2).setParameter(0, code).list();

			if (list1.size() <= 0 || list1 == null || list2.size() <= 0 || list2 == null) {
				continue;
			}
			list1 = removeNulls(list1);
			list2 = removeNulls(list2);
			if (list1.size() <= 0 || list1 == null || list2.size() <= 0 || list2 == null) {
				continue;
			}
			boolean ballGreaterThanLiang = list1.stream().allMatch(num -> num > chaju1);
			boolean b1allGreaterThanDangqijia = list2.stream().allMatch(num -> num > chaju2 && num < chaju3);
			if (ballGreaterThanLiang && b1allGreaterThanDangqijia) {
				System.out.println("--------t20----算法" + code + "符合条件" + i);
				arr.add(code);
			} else {
				System.out.println("--------t20----算法" + code + "不符合条件" + i);
			}
		}
		System.out.println("共：" + arr.size());
		String joinedString = String.join(",", arr);
		System.out.println(joinedString);
		session.beginTransaction();
		Sunfa20chengjiaoModel sm = new Sunfa20chengjiaoModel();
		sm.setDate(DateTools.getCurrentDate("yyyyMMdd"));
		sm.setAllcode(joinedString);
		sm.setType("3");
		String sql10 = "delete from sunfa20chengjiao_model where type = '3' ";
		session.createSQLQuery(sql10).executeUpdate();
		session.save(sm);
		session.getTransaction().commit();
		session.clear();
		session.close();

	}

	// 20天以内有涨停。则成交量最近5天低于3
	@Override
	public void jisuan23(JSONObject json) {
		String day = json.getString("day");
		String day1 = json.getString("day1");
		Float liang = Float.parseFloat(json.getString("liang"));

		Float jia = Float.parseFloat(json.getString("jia"));

		String sql = "select DISTINCT(t.code),t.diqv,t1.shizhi from stock t left join stock_gai_nian t1 on t1.code = t.code  where t1.shizhi >20 and t1.shizhi<200";

		Session session = ContextUtil.getSessionFactory1().openSession();
		List<Object[]> list = session.createSQLQuery(sql).list();

		String sql1 = "select t.huanshoulv from stock t  where t.code = ?0  ORDER BY t.date desc limit 0," + day1;

		String sql2 = "select t.zhandifu,t.danqianjia from stock t  where t.code = ?0  ORDER BY t.date desc limit 0," + day;

		List<String> arr = new ArrayList<String>();

		for (int i = 0; i < list.size(); i++) {

			String code = list.get(i)[0] + "";

			List<Float> list1 = session.createSQLQuery(sql1).setParameter(0, code).list();
			List<Object[]> list2 = session.createSQLQuery(sql2).setParameter(0, code).list();

			if (list1.size() <= 0 || list1 == null || list2.size() <= 0 || list2 == null) {
				continue;
			}
			list1 = removeNulls(list1);

			if (list1.size() <= 0 || list1 == null) {
				continue;
			}
			boolean b1 = list1.stream().allMatch(num -> num < liang); // 最近几天的这量代于3

			List<Float> list3 = new ArrayList<Float>(); // 涨跌幅超过5天前有一个涨停的
			List<Float> list4 = new ArrayList<Float>(); // 当前值子涨停值跌了10个点的
			for (int j = 0; j < list2.size(); j++) {
				try {
					Float zhandifu = Float.parseFloat(list2.get(j)[0] + "");
					Float dangqianjia = Float.parseFloat(list2.get(j)[1] + "");
					list3.add(zhandifu);
					list4.add(dangqianjia);
				} catch (Exception e) {
					System.out.println("值空，转换出错");
				}
			}
			if (list3.size() <= 0 || list3 == null || list4.size() <= 0 || list4 == null) {
				continue;
			}
			boolean b2 = check(list3);
			boolean b3 = check1(list4, jia);
			if (b1 && b2 && b3) {
				System.out.println("--------t20----算法" + code + "符合条件" + i);
				arr.add(code);
			} else {
				System.out.println("--------t20----算法" + code + "不符合条件" + i);
			}
		}
		System.out.println("共：" + arr.size());
		String joinedString = String.join(",", arr);
		System.out.println(joinedString);
		session.beginTransaction();
		Sunfa20chengjiaoModel sm = new Sunfa20chengjiaoModel();
		sm.setDate(DateTools.getCurrentDate("yyyyMMdd"));
		sm.setAllcode(joinedString);
		sm.setType("4");
		String sql10 = "delete from sunfa20chengjiao_model where type = '4' ";
		session.createSQLQuery(sql10).executeUpdate();
		session.save(sm);
		session.getTransaction().commit();
		session.clear();
		session.close();

	}

	public static boolean check(List<Float> list) {
		for (int i = 4; i < list.size(); i++) {
			if (list.get(i) > 9.97f) {
				return true;
			}
		}
		return false;
	}

	public static boolean check1(List<Float> list, Float jia) {

		float max = Collections.max(list);
		float first = list.get(0);
		return first < max * jia;
	}

	public static boolean check3(List<Float> list, Float jia) {

		float max = Collections.min(list);
		float first = list.get(0) - max;
		return first < max * jia;
	}

	public static float calculatePercentageDifference(List<Float> numbers) {
		// 找出最小值
		float min = Float.MAX_VALUE;
		for (Float number : numbers) {
			if (number < min) {
				min = number;
			}
		}
		// 计算第一个值与最小值的差值
		float firstNumber = numbers.get(0);
		float difference = firstNumber - min;

		// 计算差值的百分比
		float percentageDifference = (difference / min) * 100;

		return percentageDifference;
	}

	@Override
	public JSONArray selectsuanfa(JSONObject json) {
		// TODO Auto-generated method stub

		String sql = "from Sunfa20chengjiaoModel t where t.type = '" + json.getString("suanfa") + "' and t.date = '" + json.getString("date") + "'";
		Session session = ContextUtil.getSessionFactory1().openSession();
		List<Sunfa20chengjiaoModel> list = session.createQuery(sql).list();

		if (list != null && list.size() > 0) {
			Sunfa20chengjiaoModel sm = list.get(0);
			String sql1 = "from StockGaiNian t where t.code in (?0) ";
			List<StockGaiNian> list2 = session.createQuery(sql1).setParameterList(0, sm.getAllcode().split(",")).list();
			String sql2 = "select t.danqianjia from stock t  where t.code = ?0  ORDER BY t.date desc limit 0,20 ";
			String st[] = sm.getAllcode().split(",");
			JSONArray array = JSONArray.fromObject(list2);
			for (int i = 0; i < array.size(); i++) {
				List<Float> list3 = session.createSQLQuery(sql2).setParameter(0, array.getJSONObject(i).get("code")).list();
				Float f = calculatePercentageDifference(list3);
				array.getJSONObject(i).put("ji20min", f);
			}
			return setNameArr(array);
		}

		return null;
	}

	@Override
	public void jisuan24(JSONObject json) {
		String sql = "select DISTINCT(t.code),t.diqv,t1.shizhi from stock t left join stock_gai_nian t1 on t1.code = t.code  where t1.shizhi >20 and t1.shizhi<300";

		Session session = ContextUtil.getSessionFactory1().openSession();
		List<Object[]> list0 = session.createSQLQuery(sql).list();

		List<String> list = new ArrayList<String>();
		for (int i = 0; i < list0.size(); i++) {
			Object[] obj = list0.get(i);
			if ("0".equals(obj[1] + "")) {
				list.add("sh" + obj[0]);
			} else {
				list.add("sz" + obj[0]);
			}
		}

		String sql1 = "select t.date, t.shizhi,t.zhangdiefu,t.huanshoulv,t.dqj from stockqq t where t.code =?0 ORDER BY t.date desc limit 0,20";

		List<String> str3zheng = new ArrayList<String>();
		List<String> str4zheng = new ArrayList<String>();
		List<String> str5zheng = new ArrayList<String>();

		for (int i = 0; i < list.size(); i++) {
			List<Object[]> list2 = session.createSQLQuery(sql1).setParameter(0, list.get(i)).list();
			System.out.println(i + ":" + list.get(i) + ":" + list2.size());
			if (list2 != null && list2.size() >= 5) {
				Object[] obj1 = list2.get(0);
				Object[] obj2 = list2.get(1);
				Object[] obj3 = list2.get(2);
				Object[] obj4 = list2.get(3);
				Object[] obj5 = list2.get(4);
				if (Float.parseFloat(obj1[1] + "") < 20) {
					continue;
				}
				Float zdf1 = Float.parseFloat(obj1[2] + "");
				Float zdf2 = Float.parseFloat(obj2[2] + "");
				Float zdf3 = Float.parseFloat(obj3[2] + "");
				Float zdf4 = Float.parseFloat(obj4[2] + "");
				Float zdf5 = Float.parseFloat(obj5[2] + "");

				Float hsl1 = Float.parseFloat(obj1[3] + "");
				Float hsl2 = Float.parseFloat(obj2[3] + "");
				Float hsl3 = Float.parseFloat(obj3[3] + "");

				// 连续三天为正
				if (zdf1 > 0 && zdf2 > 0 && zdf3 > 0) {
					str3zheng.add(list.get(i));
				}
				// 连续四天为正
				if (zdf1 > 0 && zdf2 > 0 && zdf3 > 0 && zdf4 > 0) {
					str4zheng.add(list.get(i));
				}
				// 连续五天为正
				if (zdf1 > 0 && zdf2 > 0 && zdf3 > 0 && zdf4 > 0 && zdf5 > 0) {
					str5zheng.add(list.get(i));
				}

				if (hsl2 >= hsl1 && hsl3 >= hsl2) {

				}
			}
		}

		System.out.println("连续三天为正：" + str3zheng.size());
		System.out.println(JSONArray.fromObject(str3zheng).toString());
		System.out.println("连续四天为正：" + str4zheng.size());
		System.out.println(JSONArray.fromObject(str4zheng).toString());
		System.out.println("连续五天为正：" + str5zheng.size());
		System.out.println(JSONArray.fromObject(str5zheng).toString());
		System.out.println("共：" + str3zheng.size());
		String joinedString = String.join(",", str3zheng);
		String joinedString1 = String.join(",", str4zheng);
		String joinedString2 = String.join(",", str5zheng);
		System.out.println(joinedString);
		session.beginTransaction();
		Sunfa20chengjiaoModel sm = new Sunfa20chengjiaoModel();
		sm.setDate(DateTools.getCurrentDate("yyyyMMdd"));
		sm.setAllcode(joinedString);
		sm.setType("5");

		Sunfa20chengjiaoModel sm1 = new Sunfa20chengjiaoModel();
		sm1.setDate(DateTools.getCurrentDate("yyyyMMdd"));
		sm1.setAllcode(joinedString1);
		sm1.setType("6");

		Sunfa20chengjiaoModel sm2 = new Sunfa20chengjiaoModel();
		sm2.setDate(DateTools.getCurrentDate("yyyyMMdd"));
		sm2.setAllcode(joinedString2);
		sm2.setType("7");

		String sql10 = "delete from sunfa20chengjiao_model where type = '5' ";
		String sql11 = "delete from sunfa20chengjiao_model where type = '6' ";
		String sql12 = "delete from sunfa20chengjiao_model where type = '7' ";
		session.createSQLQuery(sql10).executeUpdate();
		session.createSQLQuery(sql11).executeUpdate();
		session.createSQLQuery(sql12).executeUpdate();
		session.save(sm);
		session.save(sm1);
		session.save(sm2);
		session.getTransaction().commit();
		session.clear();
		session.close();
//		session.beginTransaction();

//		session.createSQLQuery(sql10).executeUpdate();
//		session.save(sm);
//		session.getTransaction().commit();
//		session.clear();
//		session.close();

	}

	public JSONArray setNameArr(JSONArray array) {
		String sql = "select DISTINCT(code),t.name from stock t ";
		Session session = ContextUtil.getSessionFactory1().openSession();

		List<Object[]> list = session.createSQLQuery(sql).list();
		for (int i = 0; i < array.size(); i++) {
			JSONObject json = array.getJSONObject(i);
			for (int j = 0; j < list.size(); j++) {
				if (json.getString("code").equals(list.get(j)[0] + "")) {
					array.getJSONObject(i).put("name", list.get(j)[1]);
					break;
				}
			}
		}
		return array;
	}

	@Override
	public JSONArray jisuan25(JSONObject json) {
		// TODO Auto-generated method stub
//		String sql = "select t.code from stockqq t where t.zhangdiefu " + json.getString("jia7")
//				+ " and t.date =?0 and t.code in (select t.code from stockqq t where t.zhangdiefu  "
//				+ json.getString("jia6") + " and t.date =?1)";

		String sql = "select t1.zuigao,t1.zuidi, t1.name,t1.code,t1.zt_note,t1.shizhi,t2.gn,t1.huanshoulv,t1.cjje from stockqq t1  left join stock_cls t2 on t1.code = t2.code where t1.zhangdiefu  " + json.getString("jia7") + " and t1.date =?0 and t1.code in (select t.code from stockqq t  where t.zhangdiefu  " + json.getString("jia6") + " and t.date =?1) ";

		System.out.println(sql);

		Session session = ContextUtil.getSessionFactory1().openSession();

		List<Object[]> list = session.createSQLQuery(sql).setParameter(0, json.getString("day7")).setParameter(1, json.getString("day6")).list();
		System.out.println("共有" + list.size() + "符合条件");
		JSONArray arr = new JSONArray();
		for (int i = 0; i < list.size(); i++) {
			JSONObject json1 = new JSONObject();
			Object[] obj = list.get(i);
			json1.put("zuigao", obj[0] + "");
			json1.put("zuidi", obj[1] + "");
			json1.put("name", obj[2] + "");
			json1.put("code", obj[3] + "");
			json1.put("ztConent", obj[4] + "");
			json1.put("shizhi", obj[5] + "");
			json1.put("gn", obj[6] + "");
			json1.put("huanshoulv", obj[7] + ""); 
			String str  =obj[8] + ""; 
			json1.put("cjje", Float.parseFloat(str) /10000);
			
			
			
			
			arr.add(json1);
		}
		LocalDate today = LocalDate.now();
		LocalDate fifteenDaysAgo = today.minusDays(12);
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
		System.out.println("当前日期: " + today.format(formatter));
		System.out.println("15天前的日期: " + fifteenDaysAgo.format(formatter));
		if ("1".equals(json.get("flag"))) {
			String sql2 = "select count(*) from stockqq t where t.code =?0 and t.zhangdiefu >=8 and t.date > ?1";
			for (int i = arr.size() - 1; i >= 0; i--) {
				String code = arr.getJSONObject(i).getString("code");
				System.out.println(code);
				String count = session.createSQLQuery(sql2).setParameter(0, code).setParameter(1, fifteenDaysAgo.format(formatter)).uniqueResult().toString();
				if (Integer.parseInt(count) >= 3) {
					arr.remove(i);
				}
				if (json.containsKey("type") && "1".equals(json.getString("type"))) {
					if (Integer.parseInt(count) >= 2) {
						arr.remove(i);
					}
				}
			}
		}

		return arr;
	}

	@Override
	public JSONArray getGN(List<String> list) {
		// TODO Auto-generated method stub
		if (list.size() <= 0) {
			return null;
		}
		String sql1 = "from StockCls t where t.code in (?0) ";
		Session session = ContextUtil.getSessionFactory1().openSession();
		List<StockCls> list2 = session.createQuery(sql1).setParameterList(0, list).list();

		// String sql2 = " select t.code,t.date, t.zt_note,t.huanshoulv,t.zhangdiefu
		// from stockqq t where t.code =?0 order by t.date desc limit 0,1 ";
		String sql2 = "(select t.code,t.date, t.zt_note,t.huanshoulv,t.zhangdiefu from stockqq t where t.code in (?0)  and t.date =(select max(date) from stockqq ) )  ";
		// String sql3 = " SELECT SUM(huanshoulv) AS total_huanshoulv FROM (SELECT
		// huanshoulv FROM stockqq where code =?0 ORDER BY date DESC LIMIT 0,3)
		// subquery";
		// JSONArray jsontemp = new JSONArray();

		List<Object[]> list3 = session.createSQLQuery(sql2).setParameter(0, list).list();

		for (int i = 0; i < list2.size(); i++) {
			// Object cjh3 = session.createSQLQuery(sql3).setParameter(0,
			// list2.get(i).getCode()).uniqueResult();
			for (int j = 0; j < list3.size(); j++) {
				Object[] temp = list3.get(j);
				if (list2.get(i).getCode().equals(temp[0] + "")) {
					list2.get(i).setZtContent(list3.get(j)[2] + "");
					list2.get(i).setCjlsum(list3.get(j)[3] + "");
					list2.get(i).setZuijinZDF(list3.get(j)[4] + "");
					break;
				}
				// JSONObject jsona = new JSONObject();
				// jsona.put("huanshoulv", list3.get(j)[0] + "");
				// jsona.put("date", list3.get(j)[1] + "");
				// jsona.put("zhandifu", list3.get(j)[2] + "");
				// jsona.put("danqianjia", list3.get(j)[3] + "");
				// jsona.put("ztContent", list3.get(j)[4] + "");
				// jsontemp.add(jsona);

			}
			// list2.get(i).setCjllist(jsontemp.toString());
			// list2.get(i).setCjlsum(cjh3.toString());
		}

		return (JSONArray.fromObject(list2));

	}

	@Override
	public List<String> get1jin2Code(List<String> list2, String zuoridate, String zhangdiefu) {
		// TODO Auto-generated method stub

		String sql = "";
		for (int i = 0; i < list2.size(); i++) {

			if (i == list2.size() - 1) {
				sql += list2.get(i);
			} else {
				sql += list2.get(i) + ",";
			}

		}

		String sql1 = "select code from stockqq t where t.code in (" + sql + ") and t.zhangdiefu <= " + zhangdiefu + " and t.date =" + zuoridate;
		Session session = ContextUtil.getSessionFactory1().openSession();
		List<String> list3 = session.createSQLQuery(sql1).list();
		return list3;
	}

}
